package com.itrh.auth.service.impl;

import com.itrh.auth.domain.Permission;
import com.itrh.auth.mapper.PermissionMapper;
import com.itrh.auth.service.IPermissionService;
import com.itrh.base.service.impl.BaseServiceImpl;
import com.itrh.org.util.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author XHU_WHY
 * @since 2024-04-06
 */
@Service
public class PermissionServiceImpl extends BaseServiceImpl<Permission> implements IPermissionService {
    @Resource
    private PermissionMapper permissionMapper;
    @Override
    public Result saveOrUpdate(Permission permission) {
        try {
            if (permission.getId() == null) {
                permissionMapper.insert(permission);
            } else {
                permissionMapper.update(permission);
            }
            return Result.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("保存失败");
        }
    }

    @Override
    public Result getPermissionTree() {
        try {
            List<Permission> list = permissionMapper.selectTree();
            return Result.success(list);
        } catch (Exception e){
            e.printStackTrace();
            return Result.error("获取权限树失败");
        }
    }

    @Override
    public List<String> getPermissionByEmpId(Long id) {
        return permissionMapper.getPermissionByEmpId(id);
    }
}
